package com.pyue.eam.admin.controller;

import cn.hutool.core.lang.tree.Tree;
import com.pyue.eam.admin.api.entity.eam.EamRegion;
import com.pyue.eam.common.core.util.R;
import com.pyue.eam.regi.module.region.service.RegionService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/region")
public class EamRegionController {
    private final RegionService regionService;

    /**
     * 查询所有的城市数据树
     */
    @GetMapping("/tree")
    public R<List<Tree<String>>> cityDataTree(String name, String parentId) {
        return R.okList(regionService.cityData(name, parentId));
    }

    /**
     * 通过ID查询城市数据
     */
    @GetMapping("/{id}")
    public R<EamRegion> getById(@PathVariable Integer id) {
        return R.ok(regionService.getById(id));
    }

    /**
     * 更新城市价格
     */
    @PutMapping("/cityPrice")
    public R<Boolean> cityPrice(@RequestBody EamRegion eamRegion) {
        return R.ok(regionService.updateCityPrice(eamRegion));
    }

}
